# -*- coding: utf-8 -*-
import os,django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project_name.settings")  #django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet 报错解决
django.setup()

from django.shortcuts import render
from .models import UserMessage
# Create your views here.

def getform(request):
    # all_message = UserMessage.objects.all()
    # for message in all_message:
    #     print message.name
    if request.method == "POST":
        name = request.POST.get('name', '')
        message = request.POST.get('message', '')
        address = request.POST.get('address', '')
        email = request.POST.get('email', '')

        user_message = UserMessage()
        user_message.name = name
        user_message.message = message
        user_message.address = address
        user_message.email = email
        # user_message.object_id = "helloworld2"
        user_message.save()
    return render(request, 'message_form.html')